import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/res/gaps.dart';
import 'package:ls_work/viewmodel/medecine/choose_medicine_elder_view_model.dart';
import 'package:ls_work/widgets/common_widget.dart';

import '../../net/response/medicine_advice/medicine_elder_list_data.dart';
class ChooseMedicineElderPage extends BaseStatefulMvvmWidget{
  @override
  State<StatefulWidget> createState() => _ChooseMedicineElderState();

}

class _ChooseMedicineElderState extends BaseMvvmListState<ChooseMedicineElderViewModel,ChooseMedicineElderPage>{
  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      backgroundColor: Colours.bg_color,
      appBar: AppBar(
        title: Text('选择长者'),
      ),
      body: Column(
        children: [
          Row(
            children: [
              Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  CommonText(vm?.type.pickName,),
                  Icon(Icons.arrow_drop_down_outlined)
                ],
              ).onTap((){
                viewModel.chooseType();
              }),
              SizedBox(width: 12,),
              NoBorderInput(hintText: "请输入${vm?.type.pickId=='1'?'房间号':'长者姓名'}搜索",onChanged: (str){
                viewModel.searchName = str;
              },maxLines: 1,).setWeight(1),
              Icon(Icons.search).onTap((){
                viewModel.requestRefresh();
              })
            ],
          ).addToContainer(
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: 20.borderRadius
            ),
            margin: EdgeInsets.symmetric(horizontal: 16,vertical: 12),
            padding: EdgeInsets.symmetric(horizontal: 16,vertical: 8)
          ),
          loadingContentWidget.setWeight(1)
        ],
      ),
    );
  }

  @override
  Widget createItemWidget(int index) {
    var item = viewModel.listItems[index];
    return Row(
      children: [
        CommonText(item.customerName),
        SizedBox(width: 8,),
        CommonText(item.sexName,textSize: 14),
        SizedBox().setWeight(1),
        CommonText(item.bedNo)
      ],
    ).addToContainer(padding: EdgeInsets.symmetric(horizontal: 16,vertical: 10),color: Colors.white).onTap((){
      Go().pop(result: item);
    });
  }

  @override
  Widget get separatorDivider => Gaps.dividerLine;

  @override
  ChooseMedicineElderViewModel createViewModel() {
    return ChooseMedicineElderViewModel(context);
  }

}

Future<MedicineElderListData?> chooseMedicineElder(BuildContext context) async {
  return await Go().push(ChooseMedicineElderPage());
}

